package today.belief.courier.autoconfigure;

import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import today.belief.courier.properties.CourierProperties;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * @Author LXH
 * @Date 2019/12/18
 * @Description 动态多数据源配置
 */
@Configuration
@AutoConfigureBefore(DataSourceAutoConfiguration.class)
@EnableConfigurationProperties(CourierProperties.class)
public class CourierAutoConfiguration {

    @Resource
    private CourierProperties courier;

    @Bean
    public DataSource courierDataSource() {
        return new CourierDataSource(courier);
    }

    @Bean
    public SwitchSourceAspect switchSourceAspect() {
        return new SwitchSourceAspect();
    }

}
